package org.ccams.dao;

import java.util.List;

import org.ccams.domain.TTree;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class TTreeDAO extends SqlMapClientDaoSupport  {


    public TTreeDAO() {
        super();
    }


    public int insert(TTree record) {
        return (Integer)getSqlMapClientTemplate().update("t_tree.abatorgenerated_insert", record);
    }


    public int updateByPrimaryKey(TTree record) {
        int rows = getSqlMapClientTemplate().update("t_tree.abatorgenerated_updateByPrimaryKey", record);
        return rows;
    }

 
    public int updateByPrimaryKeySelective(TTree record) {
        int rows = getSqlMapClientTemplate().update("t_tree.abatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }
    
    public int updatePidByPrimaryKey(TTree record) {
        int rows = getSqlMapClientTemplate().update("t_tree.abatorgenerated_updatePidByPrimaryKey", record);
        return rows;
    }

    public TTree selectByPrimaryKey(Long id) {
        TTree key = new TTree();
        key.setId(id);
        TTree record = (TTree) getSqlMapClientTemplate().queryForObject("t_tree.abatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    public int deleteByPrimaryKey(Long id) {
        TTree key = new TTree();
        key.setId(id);
        int rows = getSqlMapClientTemplate().delete("t_tree.abatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }
    /**
	 * 返回指定父级id下的所有
	 * @param pid
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public  List<TTree> getByPid(String pid){
		return getSqlMapClientTemplate().queryForList("t_tree.getByPid",pid);
	}
	/**
	 * 得到所有父id
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String getPid(){	
		StringBuffer parentIDBuffer =new StringBuffer();
        parentIDBuffer.append("|");
		List<TTree> list =getSqlMapClientTemplate().queryForList("t_tree.getPid");
		for(TTree t : list){
			parentIDBuffer.append(t.getPid());
			parentIDBuffer.append("|");
		}
		//得到所有的parentDID列表（这是一个巧妙的算法^_^）
        String parentIDString = parentIDBuffer.toString();
		return parentIDString;
	}
}